package com.nic.view.widget;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.nic.view.R;


/**
 * Created by Administrator on 2018/8/22.
 */

public class SelectPicDialog extends Dialog {
    /**
     * 图库选择
     */
    private Button takePhotoBtn;
    /**
     * 拍照
     */
    private Button pickPhotoBtn;
    /**
     * 取消
     */
    private Button cancelBtn;
    private int currentType = 0;

    public void setCurrentType(int type) {
        this.currentType = type;
    }

    public SelectPicDialog(@NonNull Context context, View.OnClickListener itemsOnClick) {
        super(context, R.style.dialog_no_bg);
        setContentView(R.layout.layout_popupwindow_pic);
        Window window = this.getWindow();
        window.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);
        takePhotoBtn = (Button) findViewById(R.id.takePhotoBtn);
        pickPhotoBtn = (Button) findViewById(R.id.pickPhotoBtn);
        cancelBtn = (Button) findViewById(R.id.cancelBtn);
        // 设置按钮监听
        cancelBtn.setOnClickListener(itemsOnClick);
        pickPhotoBtn.setOnClickListener(itemsOnClick);
        takePhotoBtn.setOnClickListener(itemsOnClick);
        if (this.currentType == 2) {
            pickPhotoBtn.setVisibility(View.GONE);
            takePhotoBtn.setVisibility(View.VISIBLE);
        } else if (this.currentType == 1) {
            pickPhotoBtn.setVisibility(View.VISIBLE);
            takePhotoBtn.setVisibility(View.GONE);
        } else {
            pickPhotoBtn.setVisibility(View.VISIBLE);
            takePhotoBtn.setVisibility(View.VISIBLE);
        }
        setCanceledOnTouchOutside(true);

    }
}
